package com.hongguan.oms.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.hongguan.oms.common.Uploader;
import com.hongguan.oms.service.AttachmentService;
import com.hongguan.oms.utils.Util;

/** 
 * @author <a href="mailto:gaoxinyi@hongguaninfo.com">gaoxy</a> 
 * @version createTime:2010-2-9 ����01:18:15 
 * summary 
 */
public class FileHandler extends MultiActionController{
	
	private AttachmentService attachmentService;
	public void setAttachmentService(AttachmentService service) {
		this.attachmentService = service;
	}
	private Uploader uploader;
	public void setUploader(Uploader uploader){
		this.uploader = uploader;
	}
	
	public ModelAndView upload(HttpServletRequest request,
			HttpServletResponse respnose) throws Exception {
		ModelAndView mv = new ModelAndView("jsonHtmlView");
		String filePath = "";//uploader.upload(request);
		if (filePath == null)
			mv.addObject("success",false);
		else {
			String userid = Util.getLoginIdFromSession(request);
			String format = Util.getFileSufix(filePath);
			String note = request.getParameter("note");
			if (note == null) note = "";
			Long attachId = this.attachmentService.addFile(
					userid, filePath, format, note);
			mv.addObject("success",true);
			mv.addObject("attachId", attachId);
		}
		return mv;
	}
}
